<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Expressions (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Expressions (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Expressions (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Insn-Attributes.html" rel="up" title="Insn Attributes">
<link href="Tagging-Insns.html" rel="next" title="Tagging Insns">
<link href="Defining-Attributes.html" rel="prev" title="Defining Attributes">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en">
<div class="subsection-level-extent" id="Expressions">
<div class="nav-panel">
<p>
Next: <a href="Tagging-Insns.html" accesskey="n" rel="next">Assigning Attribute Values to Insns</a>, Previous: <a href="Defining-Attributes.html" accesskey="p" rel="prev">Defining Attributes and their Values</a>, Up: <a href="Insn-Attributes.html" accesskey="u" rel="up">Instruction Attributes</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Attribute-Expressions"><span>17.19.2 Attribute Expressions<a class="copiable-link" href="#Attribute-Expressions"> &para;</a></span></h4>
<a class="index-entry-id" id="index-attribute-expressions"></a>

<p>RTL expressions used to define attributes use the codes described above
plus a few specific to attribute definitions, to be discussed below.
Attribute value expressions must have one of the following forms:
</p>
<dl class="table">
<dt><a id="index-const_005fint-and-attributes"></a><span><code class="code">(const_int <var class="var">i</var>)</code><a class="copiable-link" href="#index-const_005fint-and-attributes"> &para;</a></span></dt>
<dd><p>The integer <var class="var">i</var> specifies the value of a numeric attribute.  <var class="var">i</var>
must be non-negative.
</p>
<p>The value of a numeric attribute can be specified either with a
<code class="code">const_int</code>, or as an integer represented as a string in
<code class="code">const_string</code>, <code class="code">eq_attr</code> (see below), <code class="code">attr</code>,
<code class="code">symbol_ref</code>, simple arithmetic expressions, and <code class="code">set_attr</code>
overrides on specific instructions (see <a class="pxref" href="Tagging-Insns.html">Assigning Attribute Values to Insns</a>).
</p>
</dd>
<dt><a id="index-const_005fstring-and-attributes"></a><span><code class="code">(const_string <var class="var">value</var>)</code><a class="copiable-link" href="#index-const_005fstring-and-attributes"> &para;</a></span></dt>
<dd><p>The string <var class="var">value</var> specifies a constant attribute value.
If <var class="var">value</var> is specified as &lsquo;<samp class="samp">&quot;*&quot;</samp>&rsquo;, it means that the default value of
the attribute is to be used for the insn containing this expression.
&lsquo;<samp class="samp">&quot;*&quot;</samp>&rsquo; obviously cannot be used in the <var class="var">default</var> expression
of a <code class="code">define_attr</code>.
</p>
<p>If the attribute whose value is being specified is numeric, <var class="var">value</var>
must be a string containing a non-negative integer (normally
<code class="code">const_int</code> would be used in this case).  Otherwise, it must
contain one of the valid values for the attribute.
</p>
</dd>
<dt><a id="index-if_005fthen_005felse-and-attributes"></a><span><code class="code">(if_then_else <var class="var">test</var> <var class="var">true-value</var> <var class="var">false-value</var>)</code><a class="copiable-link" href="#index-if_005fthen_005felse-and-attributes"> &para;</a></span></dt>
<dd><p><var class="var">test</var> specifies an attribute test, whose format is defined below.
The value of this expression is <var class="var">true-value</var> if <var class="var">test</var> is true,
otherwise it is <var class="var">false-value</var>.
</p>
</dd>
<dt><a id="index-cond-and-attributes"></a><span><code class="code">(cond [<var class="var">test1</var> <var class="var">value1</var> &hellip;] <var class="var">default</var>)</code><a class="copiable-link" href="#index-cond-and-attributes"> &para;</a></span></dt>
<dd><p>The first operand of this expression is a vector containing an even
number of expressions and consisting of pairs of <var class="var">test</var> and <var class="var">value</var>
expressions.  The value of the <code class="code">cond</code> expression is that of the
<var class="var">value</var> corresponding to the first true <var class="var">test</var> expression.  If
none of the <var class="var">test</var> expressions are true, the value of the <code class="code">cond</code>
expression is that of the <var class="var">default</var> expression.
</p></dd>
</dl>

<p><var class="var">test</var> expressions can have one of the following forms:
</p>
<dl class="table">
<dt><a id="index-const_005fint-and-attribute-tests"></a><span><code class="code">(const_int <var class="var">i</var>)</code><a class="copiable-link" href="#index-const_005fint-and-attribute-tests"> &para;</a></span></dt>
<dd><p>This test is true if <var class="var">i</var> is nonzero and false otherwise.
</p>
</dd>
<dt><a class="index-entry-id" id="index-ior-and-attributes"></a>
<a class="index-entry-id" id="index-and-and-attributes"></a>
<a id="index-not-and-attributes"></a><span><code class="code">(not <var class="var">test</var>)</code><a class="copiable-link" href="#index-not-and-attributes"> &para;</a></span></dt>
<dt><code class="code">(ior <var class="var">test1</var> <var class="var">test2</var>)</code></dt>
<dt><code class="code">(and <var class="var">test1</var> <var class="var">test2</var>)</code></dt>
<dd><p>These tests are true if the indicated logical function is true.
</p>
</dd>
<dt><a id="index-match_005foperand-and-attributes"></a><span><code class="code">(match_operand:<var class="var">m</var> <var class="var">n</var> <var class="var">pred</var> <var class="var">constraints</var>)</code><a class="copiable-link" href="#index-match_005foperand-and-attributes"> &para;</a></span></dt>
<dd><p>This test is true if operand <var class="var">n</var> of the insn whose attribute value
is being determined has mode <var class="var">m</var> (this part of the test is ignored
if <var class="var">m</var> is <code class="code">VOIDmode</code>) and the function specified by the string
<var class="var">pred</var> returns a nonzero value when passed operand <var class="var">n</var> and mode
<var class="var">m</var> (this part of the test is ignored if <var class="var">pred</var> is the null
string).
</p>
<p>The <var class="var">constraints</var> operand is ignored and should be the null string.
</p>
</dd>
<dt><a id="index-match_005ftest-and-attributes"></a><span><code class="code">(match_test <var class="var">c-expr</var>)</code><a class="copiable-link" href="#index-match_005ftest-and-attributes"> &para;</a></span></dt>
<dd><p>The test is true if C expression <var class="var">c-expr</var> is true.  In non-constant
attributes, <var class="var">c-expr</var> has access to the following variables:
</p>
<dl class="table">
<dt><var class="var">insn</var></dt>
<dd><p>The rtl instruction under test.
</p></dd>
<dt><var class="var">which_alternative</var></dt>
<dd><p>The <code class="code">define_insn</code> alternative that <var class="var">insn</var> matches.
See <a class="xref" href="Output-Statement.html">C Statements for Assembler Output</a>.
</p></dd>
<dt><var class="var">operands</var></dt>
<dd><p>An array of <var class="var">insn</var>&rsquo;s rtl operands.
</p></dd>
</dl>

<p><var class="var">c-expr</var> behaves like the condition in a C <code class="code">if</code> statement,
so there is no need to explicitly convert the expression into a boolean
0 or 1 value.  For example, the following two tests are equivalent:
</p>
<div class="example smallexample">
<pre class="example-preformatted">(match_test &quot;x &amp; 2&quot;)
(match_test &quot;(x &amp; 2) != 0&quot;)
</pre></div>

</dd>
<dt><a class="index-entry-id" id="index-leu-and-attributes"></a>
<a class="index-entry-id" id="index-lt-and-attributes"></a>
<a class="index-entry-id" id="index-gt-and-attributes"></a>
<a class="index-entry-id" id="index-gtu-and-attributes"></a>
<a class="index-entry-id" id="index-ge-and-attributes"></a>
<a class="index-entry-id" id="index-geu-and-attributes"></a>
<a class="index-entry-id" id="index-ne-and-attributes"></a>
<a class="index-entry-id" id="index-eq-and-attributes"></a>
<a class="index-entry-id" id="index-plus-and-attributes"></a>
<a class="index-entry-id" id="index-minus-and-attributes"></a>
<a class="index-entry-id" id="index-mult-and-attributes"></a>
<a class="index-entry-id" id="index-div-and-attributes"></a>
<a class="index-entry-id" id="index-mod-and-attributes"></a>
<a class="index-entry-id" id="index-abs-and-attributes"></a>
<a class="index-entry-id" id="index-neg-and-attributes"></a>
<a class="index-entry-id" id="index-ashift-and-attributes"></a>
<a class="index-entry-id" id="index-lshiftrt-and-attributes"></a>
<a class="index-entry-id" id="index-ashiftrt-and-attributes"></a>
<a id="index-le-and-attributes"></a><span><code class="code">(le <var class="var">arith1</var> <var class="var">arith2</var>)</code><a class="copiable-link" href="#index-le-and-attributes"> &para;</a></span></dt>
<dt><code class="code">(leu <var class="var">arith1</var> <var class="var">arith2</var>)</code></dt>
<dt><code class="code">(lt <var class="var">arith1</var> <var class="var">arith2</var>)</code></dt>
<dt><code class="code">(ltu <var class="var">arith1</var> <var class="var">arith2</var>)</code></dt>
<dt><code class="code">(gt <var class="var">arith1</var> <var class="var">arith2</var>)</code></dt>
<dt><code class="code">(gtu <var class="var">arith1</var> <var class="var">arith2</var>)</code></dt>
<dt><code class="code">(ge <var class="var">arith1</var> <var class="var">arith2</var>)</code></dt>
<dt><code class="code">(geu <var class="var">arith1</var> <var class="var">arith2</var>)</code></dt>
<dt><code class="code">(ne <var class="var">arith1</var> <var class="var">arith2</var>)</code></dt>
<dt><code class="code">(eq <var class="var">arith1</var> <var class="var">arith2</var>)</code></dt>
<dd><p>These tests are true if the indicated comparison of the two arithmetic
expressions is true.  Arithmetic expressions are formed with
<code class="code">plus</code>, <code class="code">minus</code>, <code class="code">mult</code>, <code class="code">div</code>, <code class="code">mod</code>,
<code class="code">abs</code>, <code class="code">neg</code>, <code class="code">and</code>, <code class="code">ior</code>, <code class="code">xor</code>, <code class="code">not</code>,
<code class="code">ashift</code>, <code class="code">lshiftrt</code>, and <code class="code">ashiftrt</code> expressions.
</p>
<a class="index-entry-id" id="index-get_005fattr"></a>
<p><code class="code">const_int</code> and <code class="code">symbol_ref</code> are always valid terms (see <a class="pxref" href="Insn-Lengths.html">Computing the Length of an Insn</a>,for additional forms).  <code class="code">symbol_ref</code> is a string
denoting a C expression that yields an <code class="code">int</code> when evaluated by the
&lsquo;<samp class="samp">get_attr_&hellip;</samp>&rsquo; routine.  It should normally be a global
variable.
</p>
</dd>
<dt><a id="index-eq_005fattr"></a><span><code class="code">(eq_attr <var class="var">name</var> <var class="var">value</var>)</code><a class="copiable-link" href="#index-eq_005fattr"> &para;</a></span></dt>
<dd><p><var class="var">name</var> is a string specifying the name of an attribute.
</p>
<p><var class="var">value</var> is a string that is either a valid value for attribute
<var class="var">name</var>, a comma-separated list of values, or &lsquo;<samp class="samp">!</samp>&rsquo; followed by a
value or list.  If <var class="var">value</var> does not begin with a &lsquo;<samp class="samp">!</samp>&rsquo;, this
test is true if the value of the <var class="var">name</var> attribute of the current
insn is in the list specified by <var class="var">value</var>.  If <var class="var">value</var> begins
with a &lsquo;<samp class="samp">!</samp>&rsquo;, this test is true if the attribute&rsquo;s value is
<em class="emph">not</em> in the specified list.
</p>
<p>For example,
</p>
<div class="example smallexample">
<pre class="example-preformatted">(eq_attr &quot;type&quot; &quot;load,store&quot;)
</pre></div>

<p>is equivalent to
</p>
<div class="example smallexample">
<pre class="example-preformatted">(ior (eq_attr &quot;type&quot; &quot;load&quot;) (eq_attr &quot;type&quot; &quot;store&quot;))
</pre></div>

<p>If <var class="var">name</var> specifies an attribute of &lsquo;<samp class="samp">alternative</samp>&rsquo;, it refers to the
value of the compiler variable <code class="code">which_alternative</code>
(see <a class="pxref" href="Output-Statement.html">C Statements for Assembler Output</a>) and the values must be small integers.  For
example,
</p>
<div class="example smallexample">
<pre class="example-preformatted">(eq_attr &quot;alternative&quot; &quot;2,3&quot;)
</pre></div>

<p>is equivalent to
</p>
<div class="example smallexample">
<pre class="example-preformatted">(ior (eq (symbol_ref &quot;which_alternative&quot;) (const_int 2))
     (eq (symbol_ref &quot;which_alternative&quot;) (const_int 3)))
</pre></div>

<p>Note that, for most attributes, an <code class="code">eq_attr</code> test is simplified in cases
where the value of the attribute being tested is known for all insns matching
a particular pattern.  This is by far the most common case.
</p>
</dd>
<dt><a id="index-attr_005fflag"></a><span><code class="code">(attr_flag <var class="var">name</var>)</code><a class="copiable-link" href="#index-attr_005fflag"> &para;</a></span></dt>
<dd><p>The value of an <code class="code">attr_flag</code> expression is true if the flag
specified by <var class="var">name</var> is true for the <code class="code">insn</code> currently being
scheduled.
</p>
<p><var class="var">name</var> is a string specifying one of a fixed set of flags to test.
Test the flags <code class="code">forward</code> and <code class="code">backward</code> to determine the
direction of a conditional branch.
</p>
<p>This example describes a conditional branch delay slot which
can be nullified for forward branches that are taken (annul-true) or
for backward branches which are not taken (annul-false).
</p>
<div class="example smallexample">
<pre class="example-preformatted">(define_delay (eq_attr &quot;type&quot; &quot;cbranch&quot;)
  [(eq_attr &quot;in_branch_delay&quot; &quot;true&quot;)
   (and (eq_attr &quot;in_branch_delay&quot; &quot;true&quot;)
        (attr_flag &quot;forward&quot;))
   (and (eq_attr &quot;in_branch_delay&quot; &quot;true&quot;)
        (attr_flag &quot;backward&quot;))])
</pre></div>

<p>The <code class="code">forward</code> and <code class="code">backward</code> flags are false if the current
<code class="code">insn</code> being scheduled is not a conditional branch.
</p>
<p><code class="code">attr_flag</code> is only used during delay slot scheduling and has no
meaning to other passes of the compiler.
</p>
</dd>
<dt><a id="index-attr"></a><span><code class="code">(attr <var class="var">name</var>)</code><a class="copiable-link" href="#index-attr"> &para;</a></span></dt>
<dd><p>The value of another attribute is returned.  This is most useful
for numeric attributes, as <code class="code">eq_attr</code> and <code class="code">attr_flag</code>
produce more efficient code for non-numeric attributes.
</p></dd>
</dl>

</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Tagging-Insns.html">Assigning Attribute Values to Insns</a>, Previous: <a href="Defining-Attributes.html">Defining Attributes and their Values</a>, Up: <a href="Insn-Attributes.html">Instruction Attributes</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
